import { defineStore } from "pinia";
import Cookies from "js-cookie";

export const useAppStore = defineStore("app", {
  state() {
    return {
      sidebar: {
        //cookie存储 字符串转数字  先用Number方法转换为数字 !!隐式类型转换为布尔值
        opened: Cookies.get("sidebarStatus")
          ? !!Number(Cookies.get("sidebarStatus"))
          : true,
      },
    };
  },
  getters: {},
  actions: {
    toggleSidebar() {
      this.sidebar.opened = !this.sidebar.opened;
      Cookies.set("sidebarStatus", Number(this.sidebar.opened) + "");
    },
  },
});
